/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dto;

import javax.mail.Message.RecipientType;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 * Message DTO
 * @author Hung Cuong <nhc.hcmuns at gmail.com>
 */
public class MessageDTO {
    private int _Id;
    private String _From;
    private String _To;
    private String _Subject;
    private String _Body;
    private String _SentDate;
    private String _Type;

    public int getId() {
        return _Id;
    }

    public void setId(int id) {
        this._Id = id;
    }

    public String getFrom() {
        return _From;
    }

    public void setFrom(String fromEmail) {
        this._From = fromEmail;
    }

    public String getTo() {
        return _To;
    }


    public void setTo(String toEmail) {
        this._To = toEmail;
    }

    public String getSubject() {
        return _Subject;
    }

    public void setSubject(String subject) {
        this._Subject = subject;
    }

    public String getBody() {
        return _Body;
    }

    public void setBody(String body) {
        this._Body = body;
    }

    public String getSentDate() {
        return _SentDate;
    }

    public void setSentDate(String Date) {
        this._SentDate = Date;
    }
    
    public String getType() {
        return _Type;
    }

    public void setType(String type) {
        this._Type = type;
    }
    
    public MimeMessage toMimeMessage(Session session) throws MessagingException {
        MimeMessage message = new MimeMessage(session);

        message.setFrom(new InternetAddress(this.getFrom()));
        message.addRecipient(RecipientType.TO, new InternetAddress(this.getTo()));
        message.setSubject(this.getSubject());
        message.setText(this.getBody());
        return message;
    }
}
